package api

import (
	"fmt"
	"strconv"

	"gitee.com/hust-ideas/little-genius-backend/model"
	"gitee.com/hust-ideas/little-genius-backend/service"
	"github.com/gin-gonic/gin"
)

// KeywordsKeywordIdGenerateQuestionPost - 使用关键词生成题目
func KeywordsKeywordIdGenerateQuestionPost(c *gin.Context) {
	s := c.MustGet("service").(*service.ServiceContext)
	req := model.KeywordsKeywordIdGenerateQuestionPostReq{}
	KeywordId := c.Param("keywordId")
	fmt.Printf("KeywordId: %s\n", KeywordId)
	// transform string to int64
	var err error
	req.KeywordId, err = strconv.ParseUint(KeywordId, 10, 64)
	if err != nil {
		c.JSON(400, gin.H{"error": err.Error()})
		return
	}
	if err := c.ShouldBindJSON(&req); err != nil {
		c.JSON(400, gin.H{"error": err.Error()})
		return
	}
	req.UserId = c.MustGet("uid").(uint64)
	fmt.Println(req)

	resp, err := s.KeywordGen(req, c.Request.Context())
	if err != nil {
		c.JSON(500, gin.H{"error": err.Error()})
		return
	}
	c.JSON(200, resp)
}
